Skip to main content

left-bracerightbrace

Type

operator

Summary

Returns a dictionary array formed from the provided list of key-value pairs.

Syntax

{ <keyLiteral> : <valueExpression> [, <keyLiteral> : <valueExpression> ...] }

Description

Use the { } operator to create a dictionary array from a list of key-value pairs.

Each value expression between { and } is evaluated and assigned to its corresponding key in the new dictionary array.

Evaluation of the value expressions proceeds from left to right, given an equivalence between a dictionary array building expression and explicit sequence of put statements. For example:

    get { \"a\": 1, \"b\": cos(0.5), \"c\": sin(0.5), \"d\": 1 }

Is equivalent to:

    put 1 into it[\"a\"]
put cos(0.5) into it[\"b\"]
put sin(0.5) into it[\"c\"]
put 1 into it[\"d\"]

Value expressions can be any constant or non-constant expression, including sequence array and dictionary array expressions.

The list of key-value pairs may be followed by an optional comma which is ignored.

If a key-value list contains duplicate keys, then the last value expression specified for a given key will be the one which is used in the final dictionary array. The value expressions are always evaluated, even if their value will be replaced by a later one against a given key. For example:

   get { \"a\": 1, \"a\": 2 }

Will result in a dictionary array with a single key "a", with value 2.

Construction of the array takes the current setting of the caseSensitive property into account and this determines whether keys are seen as duplicates or not.

In the case of the caseSensitive property being false, duplicate keys up to case will be present as the first such key, but with the last evaluated value. For example:

   set the caseSensitive to false
get { \"a\": 1, \"A\": 2 }

Will result in a dictionary array with single key "a", with value 2. This behavior is a side-effect of the equivalence of {} to a sequence of put statements in the same order as the key-value pairs.

In contrast, in the case of the caseSensitive property being true, such keys will not be duplicates. For example:

   set the caseSensitive to true
get { \"a\": 1, \"A\": 2 }

Will result in a dictionary array with two entries, one having key "a" with value 1, and the other having key "A" with value 2.

Parameters

NameTypeDescription

keyLiteral

A string or integer literal specifying the key to use for its corresponding value.

valueExpression

An expression evaluated as the value for the corresponding key.

Examples

{}
{ "foo": 1, 1: "foo" }
{ "a": 1, 2: "b", "c": 3, 4: "d", }
{ "a": [], "b": [ {}, { "foo": 1 } ], 3: [[]] }
local tFirst, tSecond
put { "foo": 1 } into tFirst
put { 1: "foo" } into tSecond
get { "a": tFirst, 2: tSecond }

glossary: array, element

glossay:

keyword: element

operator: left-bracerightbrace

property: caseSensitive

Compatibility and Support

Introduced

LiveCode 10.0

OS

mac

windows

linux

ios

android

web

Platforms

desktop

server

mobile

Thank you for your feedback!

Was this page helpful?